package com.dyz.wsw.domain.market.convert;

import com.dyz.wsw.domain.market.pojo.MarketCard;
import io.r2dbc.spi.Row;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

import java.time.Instant;

/**
 * @author dyz
 * @date 2025/1/11 20:48
 */
//todo 1.修改表映射关系（调整了表名注意修改）。2.现在所有的数据层就干一件事，就是查数据然后进行表映射。3.查出的数据后续处理就可以交给服务层了
@ReadingConverter
@Slf4j
public class MarketCardConvert implements Converter<Row, MarketCard> {

    public MarketCardConvert(){
        log.debug("创建MarketCardConvert对象：[market-card<===>MarketCardDO]");
    }

    @Override
    public MarketCard convert(Row source) {
        MarketCard marketCard = new MarketCard();
        marketCard.setId(source.get("id", Long.class));
        marketCard.setTitle(source.get("title", String.class));
        marketCard.setDescription(source.get("description", String.class));
        marketCard.setCId(source.get("c_id", Integer.class));
        marketCard.setImgUrl(source.get("img_url", String.class));
        marketCard.setModuleUrl(source.get("module_url", String.class));
        marketCard.setCommentCount(source.get("comment_count", Integer.class));
        marketCard.setLikeCount(source.get("like_count", Integer.class));
        marketCard.setViewCount(source.get("view_count", Integer.class));
        marketCard.setCreateTime(source.get("create_time", Instant.class));
        marketCard.setUpdateTime(source.get("update_time", Instant.class));
        marketCard.setShow(source.get("is_show", Integer.class) == 1);
        return marketCard;
    }
}
